// Decompiled by Jad v1.5.8g. Copyright 2001 Pavel Kouznetsov.
// Jad home page: http://www.kpdus.com/jad.html
// Decompiler options: packimports(3) 
// Source File Name:   MDGenerator.java

package gnu.crypto.prng;

import gnu.crypto.hash.HashFactory;
import gnu.crypto.hash.IMessageDigest;
import java.util.Map;

// Referenced classes of package gnu.crypto.prng:
//            BasePRNG, LimitReachedException

public class MDGenerator extends BasePRNG
{

    public MDGenerator()
    {
        super("md");
    }

    private MDGenerator(MDGenerator that)
    {
        this();
        md = that.md != null ? (IMessageDigest)that.md.clone() : null;
        buffer = (byte[])that.buffer.clone();
        ndx = that.ndx;
        initialised = that.initialised;
    }

    public Object clone()
    {
        return new MDGenerator(this);
    }

    public void setup(Map attributes)
    {
        String underlyingMD = (String)attributes.get("gnu.crypto.prng.md.hash.name");
        if(underlyingMD == null)
        {
            if(md == null)
                md = HashFactory.getInstance("sha-160");
            else
                md.reset();
        } else
        {
            md = HashFactory.getInstance(underlyingMD);
        }
        byte seed[] = (byte[])attributes.get("gnu.crypto.prng.md.seed");
        if(seed == null)
            seed = new byte[0];
        md.update(seed, 0, seed.length);
    }

    public void fillBlock()
        throws LimitReachedException
    {
        IMessageDigest mdc = (IMessageDigest)md.clone();
        buffer = mdc.digest();
        md.update(buffer, 0, buffer.length);
    }

    public static final String MD_NAME = "gnu.crypto.prng.md.hash.name";
    public static final String SEEED = "gnu.crypto.prng.md.seed";
    private IMessageDigest md;
}
